const mongoose = require('mongoose');

const productSchema = new mongoose.Schema({
  title: {
    type: String,
    required: true,
    trim: true
  },
  description: {
    type: String,
    required: true
  },
  price: {
    type: Number,
    required: true,
    min: 0
  },
  originalPrice: {
    type: Number,
    required: true,
    min: 0
  },
  category: {
    type: String,
    required: true,
    enum: ['书籍', '电子产品', '生活用品', '服装', '其他']
  },
  images: [{
    type: String  // 只存储图片URL
  }],
  condition: {
    type: String,
    required: true,
    enum: ['全新', '9成新', '8成新', '7成新', '6成新及以下']
  },
  seller: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  status: {
    type: String,
    enum: ['在售', '交易中', '已售出', '已下架'],
    default: '在售'
  },
  adminRemark: {
    type: String,
    default: ''
  },
  updatedAt: {
    type: Date
  },
  updatedBy: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  },
  createdAt: {
    type: Date,
    default: Date.now
  }
});

const Product = mongoose.model('Product', productSchema);
module.exports = Product; 